import java.util.concurrent.Semaphore;
public class Demo30 {
    public static void main(String[] args) {
        Semaphore semaphore = new Semaphore(1);
        Thread t1 = new Thread(()->{
            try {
                System.out.println("t1尝试获取资源");
                semaphore.acquire();
                System.out.println("t1获取成功");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        Thread t2 = new Thread(()->{
            try {
                System.out.println("t2尝试获取资源");
                semaphore.acquire();
                System.out.println("t2获取成功");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        t1.start();
        t2.start();
    }
}
